package com.wei.czz.common.enums.common.messageFlow;

import com.wei.czz.common.dto.common.NameValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2024-05-12 17:14:26
 * className: MessageStatusEnum
 * version: 1.0
 * description:
 */
@Getter
@AllArgsConstructor
public enum MessageStatusEnum {

    SEND_FAIL(0, "发送失败"),

    SUCCESS(1, "消费成功"),

    FAIL(2, "消费失败"),

    ;

    /**
     * 值
     */
    private final Integer value;

    /**
     * 名称
     */
    private final String name;

    /**
     * 获取名称
     * @param value 值
     * @return 名称
     */
    public static String getName(Integer value) {
        for (MessageStatusEnum messageStatusEnum : values()) {
            if (messageStatusEnum.value.equals(value)) {
                return messageStatusEnum.name;
            }
        }
        return "";
    }

    /**
     * 获取枚举列表
     */
    public static List<NameValue<Integer>> getList() {
        return Stream.of(values())
                .map(messageStatusEnum -> new NameValue<>(messageStatusEnum.name, messageStatusEnum.value))
                .collect(Collectors.toList());
    }

}
